#include "NetworkIcon.h"
#include <qnetworkaccessmanager.h>
#include <qnetworkreply.h>
#include <qnetworkrequest.h>
#include <qpixmap.h>

NetworkIcon::NetworkIcon(QWidget *parent) : QWidget(parent) 
, pixmap(new QPixmap)
, manager(new QNetworkAccessManager(this))
{
    connect(manager, &QNetworkAccessManager::finished, [&](QNetworkReply *reply){
        pixmap->loadFromData(reply->readAll());
        emit loaded(*pixmap);
    });
}

void NetworkIcon::load(QString &url) {
    manager->get(QNetworkRequest(QUrl(url)));
}